package com.dzb.langchain4j.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dzb.langchain4j.entity.AdmissionStatus;
import com.dzb.langchain4j.enums.AdmissionStatusEnum;
import com.dzb.langchain4j.mapper.AdmissionStatusMapper;
import com.dzb.langchain4j.service.AdmissionStatusService;
import com.dzb.langchain4j.util.AdmissionStatusConverter;
import com.dzb.langchain4j.vo.AdmissionStatusVO;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 录取状态服务实现类
 */
@Service
public class AdmissionStatusServiceImpl extends ServiceImpl<AdmissionStatusMapper, AdmissionStatus> 
        implements AdmissionStatusService {
    
    @Override
    public AdmissionStatus createAdmissionStatus(String name, Integer age, String address, 
                                               Integer score, AdmissionStatusEnum status) {
        AdmissionStatus admissionStatus = new AdmissionStatus();
        admissionStatus.setName(name);
        admissionStatus.setAge(age);
        admissionStatus.setAddress(address);
        admissionStatus.setScore(score);
        admissionStatus.setAdmissionStatus(status.getCode()); // 使用枚举避免魔法值
        admissionStatus.setIsDelete(0);
        admissionStatus.setCreateTime(new Date());
        admissionStatus.setUpdateTime(new Date());
        
        // 使用MyBatis-Plus的save方法保存到数据库
        save(admissionStatus);
        return admissionStatus;
    }
    
    @Override
    public AdmissionStatusVO getAdmissionStatusVO(Integer id) {
        // 使用MyBatis-Plus的getById方法从数据库获取数据
        AdmissionStatus entity = getById(id);
        return AdmissionStatusConverter.toVO(entity);
    }
    
    @Override
    public List<AdmissionStatusVO> getAdmissionStatusVOList() {
        // 使用MyBatis-Plus的list方法从数据库获取数据
        List<AdmissionStatus> entityList = list();
        return AdmissionStatusConverter.toVOList(entityList);
    }
    
    @Override
    public String getStatusDescription(Integer statusCode) {
        return AdmissionStatusEnum.getDescriptionByCode(statusCode);
    }
    
    @Override
    public boolean isAdmitted(Integer statusCode) {
        return AdmissionStatusEnum.ADMITTED.getCode().equals(statusCode);
    }
}




